/* eslint-disable no-undef */
import Vue from 'vue'
import {
  SubstituteEnum, SubstitueTranFlow, SubStituteHolder, SubstituteDate, SubstituteTof,
  SubstituteEllipsis, SubstituteFlowStandard, SubstituteNumber, SubstituteNumberFixString, SubstituteMobileDate, SubstituteSubString, SubstituteList
} from '../FilterUtil'

Vue.filter('qxSelffilter', function(value, pipeName) {
  return selffilter(value, pipeName)
})

function selffilter(val, pipeName) {
  try {
    if (!pipeName) {
      return val
    }
    if (pipeName.enum) {
      return SubstituteEnum(val, pipeName.enum)
    } else if (pipeName.placeholder) {
      return SubStituteHolder(val)
    } else if (pipeName.date) {
      return SubstituteDate(val, pipeName.date)
    } else if (pipeName.mobileDate) {
      return SubstituteMobileDate(val, pipeName.mobileDate)
    } else if (pipeName.tof) {
      return SubstituteTof(val, pipeName.tof)
    } else if (pipeName.fix) {
      return SubstituteNumberFixString(val, pipeName.fix)
    } else if (pipeName.ellipsis) {
      return SubstituteEllipsis(val, pipeName.ellipsis)
    } else if (pipeName.flow !== undefined) {
      return SubstituteFlowStandard(val)
    } else if (pipeName.number) {
      return SubstituteNumber(val)
    } else if (pipeName.tranflow) {
      return SubstitueTranFlow(val, pipeName.tranflow)
    } else if (pipeName.substr) {
      return SubstituteSubString(val, pipeName.substr)
    } else if (pipeName.list) {
      const list = pipeName.list
      return SubstituteList(val, list)
    } else if (pipeName.fun) {
      return pipeName.fun(val)
    } else {
      return val
    }
  } catch (err) {
    return val
  }
}
